//
//  bitOperate.cpp
//  learnC++
//
//  Created by apple on 2018/5/23.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "bitOperate.hpp"

void testBitOperate(){
    
    unsigned char option_viewed = 0x01;//0000 0001
    unsigned char option_edited = 0x02;//0000 0010
    unsigned char option_favorited = 0x04;//0000 0100
    unsigned char option_shared = 0x08;//0000 1000
    unsigned char option_deleted = 0x80;//1000 0000
    
    unsigned char myArticleFlags = 0;
    
    
    //查看
    myArticleFlags |= option_viewed;
    if(myArticleFlags & option_deleted){
        printf("delete");
    }else{
        printf("no");
    }
    
    myArticleFlags &= ~option_favorited;
    
    
    
}

void cppBitOperate(){
    const unsigned char option0 = 1 << 0; // 0000 0001
    const unsigned char option1 = 1 << 1; // 0000 0010
    const unsigned char option2 = 1 << 2; // 0000 0100
    const unsigned char option3 = 1 << 3; // 0000 1000
    const unsigned char option4 = 1 << 4; // 0001 0000
    const unsigned char option5 = 1 << 5; // 0010 0000
    const unsigned char option6 = 1 << 6; // 0100 0000
    const unsigned char option7 = 1 << 7; // 1000 0000
    
    
    std::bitset<8> bits(0);
    bits.set(3);//打开
    //    bits.reset(3);//关闭
    //    bits.flip(3);//翻转
    //    bits.flip();//全部翻转
    std::cout << bits.test(3) << std::endl;
    
    
    
    
    printf("KKKKk = %d\n",bits.test(2));
    printf("KKKKk = %d\n",(int)option3);
}
